<?php
declare (strict_types = 1);

namespace app\auth\model;

/**
 * @mixin \think\Model
 */
class AdminModel extends BaseModel
{
    protected $table = 'tb_admins';
    protected $append = ['type_str', 'status_str'];

    //类型
    const TYPE_SUPER = 1;
    const TYPE_NORMAL = 10;
    static $TYPE_STR = [
        self::TYPE_SUPER => '超管',
        self::TYPE_NORMAL => '员工'
    ];
    public function getTypeStrAttr($value,$data)
    {
        return @self::$TYPE_STR[$data['type']];
    }

    //状态
    const STATUS_ACTIVE = 1;
    const STATUS_DIE = 0;
    static $STATUS_STR = [
        self::STATUS_ACTIVE => '激活',
        self::STATUS_DIE => '不能登陆'
    ];
    public function getStatusStrAttr($value,$data)
    {
        return @self::$STATUS_STR[$data['status']];
    }

    const WITH_ROLE = 'role';
    public function role()
    {
        return $this->belongsTo('app\auth\model\RoleModel', 'role_id');
    }
    const WITH_DEPT = 'dept';

    public function dept()
    {
        return $this->belongsTo('app\auth\model\DeptModel', 'dept_id');
    }

    const WITH_USER_INFO = 'user_info';
    public function userInfo()
    {
        return $this->belongsTo('app\auth\model\UserModel', 'user_id')->field([
            'id',
            'username',
            'realname',
            'status',
            'reg_time',
            'reg_ip',
            'last_time',
            'last_ip',
            'phone',
            'email',
            'gender',
            'salary',
            'avatar',
            'login_times',
        ]);
    }
}
